home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Periodicals / CSMP / C.S.M.P. Digest, Issue 3.003 < prev    next >
Internet Message Format  |  1994-06-09  |  34KB

  1. From: pottier@clipper.ens.fr (Francois Pottier)
  2. Subject: C.S.M.P. Digest, Issue 3
  3. Date: Mon, 14 Mar 94 14:36:48 MET
  4.  
  5. C.S.M.P. Digest             Mon, 14 Mar 94       Volume 3 : Issue 3
  6.  
  7. Today's Topics:
  8.  
  9.         A4 Worlds in MPW c-c++? Is it possible?
  10.         Documented sliders?
  11.         How do I know if AppleTalk uses print port?
  12.         How to convert date to seconds *correctly*?
  13.         To Handle or not to Handle?
  14.         When to unlock?
  15.  
  16.  
  17.  
  18. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  19. (pottier@clipper.ens.fr).
  20.  
  21. The digest is a collection of article threads from the internet newsgroup
  22. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  23. regularly and want an archive of the discussions.  If you don't know what a
  24. newsgroup is, you probably don't have access to it.  Ask your systems
  25. administrator(s) for details.  If you don't have access to news, you may
  26. still be able to post messages to the group by using a mail server like
  27. anon.penet.fi (mail help@anon.penet.fi for more information).
  28.  
  29. Each issue of the digest contains one or more sets of articles (called
  30. threads), with each set corresponding to a 'discussion' of a particular
  31. subject.  The articles are not edited; all articles included in this digest
  32. are in their original posted form (as received by our news server at
  33. nef.ens.fr).  Article threads are not added to the digest until the last
  34. article added to the thread is at least two weeks old (this is to ensure that
  35. the thread is dead before adding it to the digest).  Article threads that
  36. consist of only one message are generally not included in the digest.
  37.  
  38. The digest is officially distributed by two means, by email and ftp.
  39.  
  40. If you want to receive the digest by mail, send email to listserv@ens.fr
  41. with no subject and one of the following commands as body:
  42.     help                        Sends you a summary of commands
  43.     subscribe csmp-digest Your Name    Adds you to the mailing list
  44.     signoff csmp-digest            Removes you from the list
  45. Once you have subscribed, you will automatically receive each new
  46. issue as it is created.
  47.  
  48. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  49. Questions related to the ftp site should be directed to
  50. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  51. digest are available there.
  52.  
  53. Also, the digests are available to WAIS users as comp.sys.mac.programmer.src.
  54.  
  55.  
  56. -------------------------------------------------------
  57.  
  58. >From btodorof@hmc.edu. (Brian Todoroff)
  59. Subject: A4 Worlds in MPW c-c++? Is it possible?
  60. Date: 26 Feb 1994 08:51:25 GMT
  61. Organization: Harvey Mudd College, Claremont CA
  62.  
  63. Does anyone know if it is possible to do A4 worlds such as those in
  64. Think C in MPW C.  This would be very useful to me in writing some
  65. external code modules for Photoshop.  Please help if you can.
  66.  
  67. +++++++++++++++++++++++++++
  68.  
  69. >From macguru@halcyon.com. (Allan Foster)
  70. Date: 27 Feb 1994 22:22:01 GMT
  71. Organization: Guru Inc
  72.  
  73. In article <2kn2id$pvi@jaws.cs.hmc.edu>
  74. btodorof@hmc.edu. (Brian Todoroff) writes:
  75.  
  76. > Does anyone know if it is possible to do A4 worlds such as those in
  77. > Think C in MPW C.  This would be very useful to me in writing some
  78. > external code modules for Photoshop.  Please help if you can.
  79.  
  80. Well, no.  Not A4 worlds exactly.  But it is fairly easy to use A5
  81. worlds from stand alone code resources in MPW.  For MPW C, it is very
  82. check out technote 256 to show you how to do it.
  83.  
  84. Doing it with MPW C++ is a little more exciting.  The main problem is
  85. dealing with static constructors, and the need for a jump table.  I
  86. wrote a paper for MacHack 91 about doing this, and the code was
  87. released public domain.  I know it is up on AOL, and on CI$,  and is
  88. probv available on one of the internet acrhives as well.
  89.  
  90. Regards
  91.  
  92. Allan Foster
  93.  
  94. ----------------------------------------------------------
  95. I am responsible for what I say and do. -- Allan Foster --
  96.  
  97. ---------------------------
  98.  
  99. >From hellstrm@access3.digex.net (Ben Hellstrom)
  100. Subject: Documented sliders?
  101. Date: 21 Feb 1994 14:44:13 -0500
  102. Organization: Express Access Online Communications, Greenbelt, MD USA
  103.  
  104. I am trying to put a slider in a modeless dialog.  I have tried swiping
  105. the slider from the "Sound" CDEV and also from "Appmaker" (which I own).
  106. After I load in the resource and set up the contrlRect, contrlValue, etc
  107. the slider comes up looking OK and is updated properly.  Furthermore,
  108. when I click on it, FindWindow() returns a code of 'inThumb'.  But when
  109. I try to track it the slider thumb just sits there. TrackControl doesn't
  110. return until I release the mouse button, but the contrlValue field is
  111. unchanged.
  112.  
  113. Any suggestions? 
  114.  
  115. Are there any *documented* slider CNTL resources around.  Without
  116. any documentation, they are hard to figure out.  I searched through
  117. Apple's IM and the TNs and didn't find anything under "slider".
  118.  
  119. Thanks for any help.
  120.  
  121. Ben Hellstrom
  122. hellstrm@access.digex.net
  123.  
  124.  
  125. +++++++++++++++++++++++++++
  126.  
  127. >From marshall@kauri.vuw.ac.nz (Stephen Marshall)
  128. Date: 24 Feb 1994 20:54:50 GMT
  129. Organization: Victoria University of Wellington
  130.  
  131. In article <2kb2ud$nth@access3.digex.net>, hellstrm@access3.digex.net (Ben
  132. Hellstrom) wrote:
  133.  
  134. > Are there any *documented* slider CNTL resources around.  Without
  135. > any documentation, they are hard to figure out.  I searched through
  136. > Apple's IM and the TNs and didn't find anything under "slider".
  137. > Thanks for any help.
  138. > Ben Hellstrom
  139. > hellstrm@access.digex.net
  140.  
  141. Somewhat foolishly I have posted a request for such a beast on
  142. Alt.sources.mac (apparently a no-no). No responses yet. For such a commonly
  143. implemented beast it seems to be quite uncommon to post code for it. If
  144. anyone does post source or an explanation of how to use the sound cdevs
  145. CNTL I would be greatful. 
  146.  
  147. PS: is there not a slight copyright problem with using the CNTL resource
  148. out of the Sound CDEV? I would have thought that Apples copyright would
  149. prohibit plundering?
  150.  
  151. Stephen
  152. -- 
  153. Macintosh Consultant                              Marshall@kauri.vuw.ac.nz
  154. Victoria University of Wellington
  155. New Zealand
  156.  
  157. +++++++++++++++++++++++++++
  158.  
  159. >From egurney@vcd.hp.com (Eddy J. Gurney)
  160. Date: Fri, 25 Feb 1994 18:23:20 GMT
  161. Organization: Hewlett-Packard VCD
  162.  
  163. Stephen Marshall (marshall@kauri.vuw.ac.nz) wrote:
  164. >In article <2kb2ud$nth@access3.digex.net>, hellstrm@access3.digex.net (Ben
  165. >Hellstrom) wrote:
  166. >> Are there any *documented* slider CNTL resources around.  Without
  167. >> any documentation, they are hard to figure out.  I searched through
  168. >> Apple's IM and the TNs and didn't find anything under "slider".
  169.  
  170. >Somewhat foolishly I have posted a request for such a beast on
  171. >Alt.sources.mac (apparently a no-no). No responses yet. For such a commonly
  172. >implemented beast it seems to be quite uncommon to post code for it. If
  173. >anyone does post source or an explanation of how to use the sound cdevs
  174. >CNTL I would be greatful. 
  175.  
  176. There is a very nice freeware slider CDEF that is used in Jersey 
  177. Scientific's CMaster.  The only reason I know it's freeware is from the 
  178. little blurb in the manual (which is at home right now).  If someone
  179. knows where this CDEF is available as a nice little package, with
  180. documentation and maybe even (we can always hope) source, please let
  181. us know!
  182.  
  183. If no one can find it, I'll extract the CDEF and explain how it works
  184. (someone sent me e-mail a while ago explaining that it is pretty easy
  185. to use, just use SetMinCtrl/SetMaxCtrl, etc.) in a short read me and
  186. submit it to alt.sources.mac...
  187.  
  188. --
  189. Eddy J. Gurney N8FPW   Hewlett-Packard Company, Vancouver (USA!) Division
  190. egurney@vcd.hp.com                       #include <standard-disclaimer.h>
  191. "Failures are divided into two classes-- those who thought and never did,
  192.       and those who did and never thought."     John Charles Salak
  193.  
  194. +++++++++++++++++++++++++++
  195.  
  196. >From hpoppe@ncar.ucar.edu (Herb Poppe)
  197. Date: 25 Feb 1994 19:17:04 GMT
  198. Organization: National Center for Atmospheric Research
  199.  
  200. In article <marshall-250294095436@makomako.its.vuw.ac.nz> 
  201. marshall@kauri.vuw.ac.nz (Stephen Marshall) writes:
  202.  
  203. > In article <2kb2ud$nth@access3.digex.net>, hellstrm@access3.digex.net 
  204. (Ben
  205. > Hellstrom) wrote:
  206. >  
  207. > > Are there any *documented* slider CNTL resources around.  Without
  208. > > any documentation, they are hard to figure out.  I searched through
  209. > > Apple's IM and the TNs and didn't find anything under "slider".
  210. > > ...
  211. > Somewhat foolishly I have posted a request for such a beast on
  212. > Alt.sources.mac (apparently a no-no). No responses yet. For such a 
  213. commonly
  214. > implemented beast it seems to be quite uncommon to post code for it. If
  215. > anyone does post source or an explanation of how to use the sound cdevs
  216. > CNTL I would be greatful. 
  217. >...
  218.  
  219. Source code (in C) for a slider CDEF (horiz. orientation only) is 
  220. available at the alt.sources.mac archive:
  221.  
  222. ftpbio.bgsu.edu
  223.  
  224. in:
  225.  
  226. "/Bio Mail Server/ftp/pub/alt.sources.mac/"
  227.  
  228. as:
  229.  
  230. cdef-slider.cpt
  231. cdef-slider.info
  232.  
  233. Herb Poppe                 National Center for Atmospheric Research (NCAR)
  234. hpoppe@ncar.ucar.edu       1850 Table Mesa Dr.
  235. (303) 497-1296             Boulder, CO  80303
  236.  
  237. +++++++++++++++++++++++++++
  238.  
  239. >From hellstrm@access2.digex.net (Ben Hellstrom)
  240. Date: 26 Feb 1994 14:30:41 -0500
  241. Organization: Express Access Online Communications, Greenbelt, MD USA
  242.  
  243. In article <marshall-250294095436@makomako.its.vuw.ac.nz>,
  244. Stephen Marshall <marshall@kauri.vuw.ac.nz> wrote:
  245. >In article <2kb2ud$nth@access3.digex.net>, hellstrm@access3.digex.net (Ben
  246. >Hellstrom) wrote:
  247. >> Are there any *documented* slider CNTL resources around.  Without
  248. >> any documentation, they are hard to figure out.  I searched through
  249. >> Apple's IM and the TNs and didn't find anything under "slider".
  250. >> 
  251. >> Thanks for any help.
  252. >> 
  253. >> Ben Hellstrom
  254. >> hellstrm@access.digex.net
  255. >
  256. >Somewhat foolishly I have posted a request for such a beast on
  257. >Alt.sources.mac (apparently a no-no). No responses yet. For such a commonly
  258. >implemented beast it seems to be quite uncommon to post code for it. If
  259. >anyone does post source or an explanation of how to use the sound cdevs
  260. >CNTL I would be greatful. 
  261. >
  262. >PS: is there not a slight copyright problem with using the CNTL resource
  263. >out of the Sound CDEV? I would have thought that Apples copyright would
  264. >prohibit plundering?
  265. >
  266. >Stephen
  267. >-- 
  268. The sound CDEV is already in public domain (ftp.apple.com) with liscence
  269. to copy.  I didn't intend to distribute it. BTW, I also own AppMaker 1.5.4
  270. which *also* has the identical slider and liscence to distribute.  The
  271. darndest thing is that I can easily put together an AppMaker project where
  272. the slider works but when I transfer the code resources over to my project
  273. it stops working!!
  274.  
  275. Ben Hellstrom
  276. hellstrm@access.digex.net
  277.  
  278.  
  279.  
  280. ---------------------------
  281.  
  282. >From johnc@flora.ruakura.cri.nz (John Curtis)
  283. Subject: How do I know if AppleTalk uses print port?
  284. Date: 21 Feb 1994 20:48:20 GMT
  285. Organization: Hort+Research
  286.  
  287. How do I find out if AppleTalk is controlling the printer port?
  288.  
  289. I can check to see if the serial drivers are in use via CRMIsDriverOpen().
  290. Likewise I can see if .MPP or .ATP is open, but can't tell if they're using
  291. ethernet or the printer port...
  292.  
  293. Basically I want my app to ask before stealing the printer port...
  294.  
  295. Thanks!
  296. -- 
  297. -----------------------------------------------------------------------------
  298. John Curtis            | 
  299. Hort+Research          |                  johnc@flora.ruakura.cri.nz
  300. Hamilton, New Zealand  |                  curtisj@ruakura.cri.nz
  301.  
  302. +++++++++++++++++++++++++++
  303.  
  304. >From Bob@lapwing.demon.co.uk (Bob Lindsey)
  305. Date: Tue, 22 Feb 1994 05:35:50 +0000
  306. Organization: LapWing Communications Ltd
  307.  
  308. In article <johnc-220294085249@160.4.128.121>
  309.            johnc@flora.ruakura.cri.nz "John Curtis" writes:
  310. > How do I find out if AppleTalk is controlling the printer port?
  311.  
  312. IM vol II, pages 304 to 305 cover this. 
  313.  
  314. -- 
  315. Bob Lindsey on bob@lapwing.demon.co.uk
  316.  
  317. +++++++++++++++++++++++++++
  318.  
  319. >From d88-jwa@hemul.nada.kth.se (Jon W‰tte)
  320. Date: 22 Feb 1994 17:09:22 GMT
  321. Organization: Royal Institute of Technology, Stockholm, Sweden
  322.  
  323. In <johnc-220294085249@160.4.128.121> johnc@flora.ruakura.cri.nz (John Curtis) writes:
  324.  
  325. >How do I find out if AppleTalk is controlling the printer port?
  326. >Basically I want my app to ask before stealing the printer port...
  327.  
  328. Just call OpenDriver on the out port; if LocalTalk is using it,
  329. you will get a port busy error back.
  330.  
  331. Of course, you should use the Comms Resource Manager to build
  332. a pop-up menu for the user to selects what port to use. See
  333. code in the FAQ.
  334. -- 
  335.  -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
  336.  
  337.    What we need is a good GNU [...] licence manager implementation.
  338.                      -- Raphael Manfredi
  339.  
  340. +++++++++++++++++++++++++++
  341.  
  342. >From leonardr@netcom.com (Leonard Rosenthol)
  343. Date: Wed, 23 Feb 1994 18:58:51 GMT
  344. Organization: Aladdin Systems, Inc.
  345.  
  346. In article <2kde82$836@news.kth.se>, d88-jwa@hemul.nada.kth.se (Jon Wtte)
  347. wrote:
  348.  
  349. > In <johnc-220294085249@160.4.128.121> johnc@flora.ruakura.cri.nz (John Curtis) writes:
  350. > >How do I find out if AppleTalk is controlling the printer port?
  351. > >Basically I want my app to ask before stealing the printer port...
  352. > Just call OpenDriver on the out port; if LocalTalk is using it,
  353. > you will get a port busy error back.
  354.      Nope, won't work!   _OpenDriver does NOT return "Port in Use" :(.
  355.  
  356.     Also, the other issue that no one has yet brought up is that on certain
  357. machines (ie. Duos) there is only ONE external serial port which doubles as
  358. both modem & printer port.   This is a very special case you need to worry
  359. about when trying things like this.
  360.  
  361. Leonard
  362. --------------------------------------------------------------------------
  363. Leonard Rosenthol                      Internet:       leonardr@netcom.com
  364. Director of Advanced Technology        AppleLink:      MACgician
  365. Aladdin Systems, Inc.                  GEnie:          MACgician
  366.  
  367. +++++++++++++++++++++++++++
  368.  
  369. >From jvp@tools1.ee.iastate.edu (Jim Van Peursem)
  370. Date: 24 Feb 94 21:55:42 GMT
  371. Organization: Iowa State University, Ames, Iowa
  372.  
  373.  
  374. >> In <johnc-220294085249@160.4.128.121> johnc@flora.ruakura.cri.nz (John Curtis) writes:
  375. >> 
  376. >> >How do I find out if AppleTalk is controlling the printer port?
  377. >> >Basically I want my app to ask before stealing the printer port...
  378.  
  379. >In article <2kde82$836@news.kth.se>, d88-jwa@hemul.nada.kth.se (Jon Wtte)
  380. >wrote:
  381. >> Just call OpenDriver on the out port; if LocalTalk is using it,
  382. >> you will get a port busy error back.
  383.  
  384. In <leonardr-230294105851@leonardr.slip.netcom.com> leonardr@netcom.com (Leonard Rosenthol) writes:
  385.  
  386. >     Nope, won't work!   _OpenDriver does NOT return "Port in Use" :(.
  387.  
  388.   It returns error -97 (portInUse) every time I do it. This may be on
  389. the particular machines I'm testing this on, but I doubt it. Error -97
  390. is an AppleTalk error.
  391.  
  392.   This may be confused with "how do I tell if a port is open" which is
  393. NOT possible. But if the port is using AppleTalk, it IS possible.
  394.  
  395. >    Also, the other issue that no one has yet brought up is that on certain
  396. >machines (ie. Duos) there is only ONE external serial port which doubles as
  397. >both modem & printer port.   This is a very special case you need to worry
  398. >about when trying things like this.
  399.  
  400.   Or worse yet, inconsistancies in the API between machines. Read my
  401. message regarding the PB100 difference I recently discovered.
  402.  
  403. +---------------------------------------------------------------+
  404. | Jim Van Peursem - Ph.D. Candidate - Ham Radio -> KE0PH        |
  405. | Department of Electrical Engineering and Computer Engineering |
  406. | Iowa State University - Ames, IA 50011 : (515) 294-8339       |
  407. | internet - jvp@iastate.edu  -or-  jvp@cpre1.ee.iastate.edu    |
  408. +---------------------------------------------------------------+
  409.  
  410. +++++++++++++++++++++++++++
  411.  
  412. >From egurney@vcd.hp.com (Eddy J. Gurney)
  413. Date: Fri, 25 Feb 1994 18:45:24 GMT
  414. Organization: Hewlett-Packard VCD
  415.  
  416. Jim Van Peursem (jvp@tools1.ee.iastate.edu) wrote:
  417.  
  418. >>> In <johnc-220294085249@160.4.128.121> johnc@flora.ruakura.cri.nz writes:
  419. >>> 
  420. >>> >How do I find out if AppleTalk is controlling the printer port?
  421. >>> >Basically I want my app to ask before stealing the printer port...
  422.  
  423. >  It returns error -97 (portInUse) every time I do it. This may be on
  424. >the particular machines I'm testing this on, but I doubt it. Error -97
  425. >is an AppleTalk error.
  426.  
  427. >  This may be confused with "how do I tell if a port is open" which is
  428. >NOT possible. But if the port is using AppleTalk, it IS possible.
  429.  
  430. Why is it NOT possible?  Can't you call GetDCtrlEntry on ports 5,6,7,8
  431. (depending on which port you want to know is open... .Ain, .Aout, .Bin,
  432. or .Bout, respectively) and check bit 5 of the dCtlFlags, which is set
  433. if the driver is open?
  434.  
  435. This should work for the built-in ports; don't know how you'd do it for 
  436. Comm Toolbox drivers (since you don't know the driver's refNum... or
  437. do you?) 
  438.  
  439. --
  440. Eddy J. Gurney N8FPW   Hewlett-Packard Company, Vancouver (USA!) Division
  441. egurney@vcd.hp.com                       #include <standard-disclaimer.h>
  442. "Failures are divided into two classes-- those who thought and never did,
  443.       and those who did and never thought."     John Charles Salak
  444.  
  445. +++++++++++++++++++++++++++
  446.  
  447. >From leonardr@netcom.com (Leonard Rosenthol)
  448. Date: Fri, 25 Feb 1994 23:13:12 GMT
  449. Organization: Aladdin Systems, Inc.
  450.  
  451. In article <CLsMro.Dn7@vcd.hp.com>, egurney@vcd.hp.com (Eddy J. Gurney)
  452. wrote:
  453.  
  454. > Jim Van Peursem (jvp@tools1.ee.iastate.edu) wrote:
  455. > >  This may be confused with "how do I tell if a port is open" which is
  456. > >NOT possible. But if the port is using AppleTalk, it IS possible.
  457. > Why is it NOT possible?  Can't you call GetDCtrlEntry on ports 5,6,7,8
  458. > (depending on which port you want to know is open... .Ain, .Aout, .Bin,
  459. > or .Bout, respectively) and check bit 5 of the dCtlFlags, which is set
  460. > if the driver is open?
  461.      You can certainly do this - works like a champ and it is how most
  462. applications today check for "port in use" since _OpenDriver is not
  463. guaranteed to do it (see appropriate Tech Note).
  464.  
  465. > This should work for the built-in ports; don't know how you'd do it for 
  466. > Comm Toolbox drivers (since you don't know the driver's refNum... or
  467. > do you?) 
  468.      You can get the names of each port via the Communications Resource
  469. Manager (CRM), and then walk through the DCE's to find the entry for the
  470. port in question.
  471.  
  472. Leonard
  473. --------------------------------------------------------------------------
  474. Leonard Rosenthol                      Internet:       leonardr@netcom.com
  475. Director of Advanced Technology        AppleLink:      MACgician
  476. Aladdin Systems, Inc.                  GEnie:          MACgician
  477.  
  478. +++++++++++++++++++++++++++
  479.  
  480. >From jvp@tools1.ee.iastate.edu (Jim Van Peursem)
  481. Date: 26 Feb 94 20:18:14 GMT
  482. Organization: Iowa State University, Ames, Iowa
  483.  
  484. >> Jim Van Peursem (jvp@tools1.ee.iastate.edu) wrote:
  485. >> 
  486. >> >  This may be confused with "how do I tell if a port is open" which is
  487. >> >NOT possible. But if the port is using AppleTalk, it IS possible.
  488.  
  489. >In article <CLsMro.Dn7@vcd.hp.com>, egurney@vcd.hp.com (Eddy J. Gurney)
  490. >wrote:
  491.  
  492. >> Why is it NOT possible?  Can't you call GetDCtrlEntry on ports 5,6,7,8
  493. >> (depending on which port you want to know is open... .Ain, .Aout, .Bin,
  494. >> or .Bout, respectively) and check bit 5 of the dCtlFlags, which is set
  495. >> if the driver is open?
  496.  
  497. In <leonardr-250294151312@leonardr.slip.netcom.com> leonardr@netcom.com (Leonard Rosenthol) writes:
  498.  
  499. >     You can certainly do this - works like a champ and it is how most
  500. >applications today check for "port in use" since _OpenDriver is not
  501. >guaranteed to do it (see appropriate Tech Note).
  502.  
  503.   Ah, but is bit 5 guaranteed? From the tech note it looks like a bit of
  504. a kludge. From the language, is sounded like it's how the CRM does it, but
  505. it's not guaranteed.
  506.  
  507. +---------------------------------------------------------------+
  508. | Jim Van Peursem - Ph.D. Candidate - Ham Radio -> KE0PH        |
  509. | Department of Electrical Engineering and Computer Engineering |
  510. | Iowa State University - Ames, IA 50011 : (515) 294-8339       |
  511. | internet - jvp@iastate.edu  -or-  jvp@cpre1.ee.iastate.edu    |
  512. +---------------------------------------------------------------+
  513.  
  514. ---------------------------
  515.  
  516. >From cbo@cs.toronto.edu (Calvin Bruce Ostrum)
  517. Subject: How to convert date to seconds *correctly*?
  518. Date: 24 Feb 94 19:56:23 GMT
  519. Organization: Department of Computer Science, University of Toronto
  520.  
  521.  
  522. This may strike people as an ignorant and trivial question, but I need
  523. to know the answer anyway.  How does one convert a date (y/m/d h:m:s) to
  524. seconds elapsed since Jan 1 1904?  I don't have very complete documentation
  525. for the tools I have available, and in MPW 3.2 am using mktime.  This seems
  526. to pick up the local time zone okay, but it does not seem to pick up whether
  527. daylight savings time is active.  This is what I need it to do.  When I read
  528. in a file of dates without timezone specified, it should use the local time
  529. zone, which it does.  But it should also subtract an hour from the date 
  530. before doing the conversion if the date is during the time of year when
  531. daylight savings time is active.  This it does not do.  Is there something
  532. I can set to make it do this?  (If not, is there a simple uniform rule that
  533. determines when dst stops and starts? I suppose I should have picked this
  534. rule up by now, but I haven't).
  535.  
  536. Please email responses.  Thank you.
  537.  
  538. ---------------------------------------------------------------------------
  539. Calvin Ostrum                                            cbo@cs.toronto.edu
  540. ---------------------------------------------------------------------------
  541.   It is a far, far better thing to have a firm anchor in nonsense than
  542.   to put out on the troubled seas of thought.  -- John Kenneth Galbraith
  543. ---------------------------------------------------------------------------
  544.  
  545. +++++++++++++++++++++++++++
  546.  
  547. >From resnick@cogsci.uiuc.edu (Pete Resnick)
  548. Date: Sun, 27 Feb 1994 13:10:02 -0600
  549. Organization: University of Illinois at Urbana-Champaign
  550.  
  551. In article <94Feb24.145607est.48169@neat.cs.toronto.edu>,
  552. cbo@cs.toronto.edu (Calvin Bruce Ostrum) wrote:
  553.  
  554. >This may strike people as an ignorant and trivial question, but I need
  555. >to know the answer anyway.  How does one convert a date (y/m/d h:m:s) to
  556. >seconds elapsed since Jan 1 1904?
  557.  
  558. The system routines String2Date and String2Time will convert string
  559. representations into a date record. These will work for all kinds of
  560. international representations and other variations on the standard by
  561. using the system tokenizer. The date record can be converted to number of
  562. seconds since 1/1/1904 by using LongDate2Secs.
  563.  
  564. >This seems to pick up the local time zone okay, but it does not seem to pick
  565. >up whether daylight savings time is active. This is what I need it to do. When
  566. >I read in a file of dates without timezone specified, it should use the local
  567. >time zone, which it does. But it should also subtract an hour from the date
  568. >before doing the conversion if the date is during the time of year when
  569. >daylight savings time is active. This it does not do. Is there something I can
  570. >set to make it do this? (If not, is there a simple uniform rule that
  571. >determines when dst stops and starts? I suppose I should have picked this rule
  572. >up by now, but I haven't).
  573.  
  574. The rules for daylight savings time not only vary from country to country,
  575. but they also vary within countries. (Arizona and parts of Indiana do not
  576. use daylight savings). The only way to account for it is to have the time
  577. zone encoded in the date string itself, either using rules which tell you
  578. whether daylight savings is in effect, like using "CST" for Central
  579. Standard Time and "CDT" for Central Daylight Time,  or using an absolute
  580. offset from GMT, like "-0600" for Central Standard Time (6 hours less than
  581. GMT) or "-0500" for Central Daylight Time (5 hours less than GMT).
  582.  
  583. I am working on a routine that uses all of the international routines
  584. properly to encode and decode such strings according to RFC 822 and RFC
  585. 1123 rules, including parsing out comments. I will post it to the net when
  586. I am finished.
  587.  
  588. pr
  589. -- 
  590. Pete Resnick        (...so what is a mojo, and why would one be rising?)
  591. Graduate assistant - Philosophy Department, Gregory Hall, UIUC
  592. System manager - Cognitive Science Group, Beckman Institute, UIUC
  593. Internet: resnick@cogsci.uiuc.edu
  594.  
  595. ---------------------------
  596.  
  597. >From francis@pinza.demon.co.uk (Francis H. Knight)
  598. Subject: To Handle or not to Handle?
  599. Date: Fri, 25 Feb 1994 19:33:16 GMT
  600. Organization: Hertfordshire Mac Oasis
  601.  
  602.  
  603. Recently finding myself with an unanticipated amount of free time, I'm
  604. using
  605. the opportunity to get up to speed with Think C (5.0.4).
  606.  
  607. I've got myself a deeply nested struct, which contains a load of
  608. configuration stuff, etcetera, and I've referred to this struct by a
  609. Handle,
  610. so the memory manager those kind folks at Apple gave us can do its stuff.
  611. Now, a lot of the general-purpose lower-level functions operate on
  612. components
  613. of the struct, so I'm dereferencing them before entering the functions. 
  614.  
  615. I'm finding it very laborious, and not very creative, to work out where to
  616. bracket (de-)references to the struct with HLock/HUnlock, given that a heap
  617. compaction trigger may be hidden within several layers of function calls.
  618. In
  619. fact, I'm sure I've missed some, as I'm still experiencing Bus Errors.
  620.  
  621. To help my thinking, can anyone offer any good:
  622.  
  623.       Methods of deciding where to HLock/HUnlock? I'm using the manual method
  624.       of combing through my code line by line and checking against the list
  625.       of memory-moving routines in Inside Mac. I feel my Mac ought to be able 
  626.       to flag the potential triggers for me!
  627.     
  628.       Criteria for judging at the outset of a project whether the hassle
  629.       of correct HLock/HUnlocking is going to outweigh the benefits of using 
  630.       NewHandle over NewPtr?
  631.     
  632.       Methods for debugging CDEVs under System 7? Or is this problem a good 
  633.       reason to create the interface as a small Application, in this age
  634.       of MultiFinder and AppleEvents?
  635.     
  636.     
  637. Cheers and thanks,
  638.  
  639.  
  640. Francis K.
  641.  
  642. At a Mac Oasis Somewhere in Suburban Hertfordshire
  643.  
  644. +++++++++++++++++++++++++++
  645.  
  646. >From jwbaxter@olympus.net (John W. Baxter)
  647. Date: Fri, 25 Feb 1994 15:04:07 -0800
  648. Organization: Internet for the Olympic Peninsula
  649.  
  650. In article <francis-250294193316@pinza.demon.co.uk>,
  651. francis@pinza.demon.co.uk (Francis H. Knight) wrote:
  652.  
  653. > I'm finding it very laborious, and not very creative, to work out where to
  654. > bracket (de-)references to the struct with HLock/HUnlock, given that a heap
  655. > compaction trigger may be hidden within several layers of function calls.
  656. > In
  657. > fact, I'm sure I've missed some, as I'm still experiencing Bus Errors.
  658. > To help my thinking, can anyone offer any good:
  659. >       Methods of deciding where to HLock/HUnlock? I'm using the manual method
  660. >       of combing through my code line by line and checking against the list
  661. >       of memory-moving routines in Inside Mac. I feel my Mac ought to be able 
  662. >       to flag the potential triggers for me!
  663.  
  664. Any function call may move memory (by loading a segment), unless you *KNOW*
  665. that every segment which might be called by the function you call is
  666. already loaded, and that the function you call will never be modified to
  667. change what you once knew.  IMHO:  assume a function call moves memory. 
  668. Someone may "improve" the code next week.  And of course:  "that little
  669. change couldn't hurt anything, we don't need to retest before the
  670. deadline."
  671.  
  672. Even those traps listed as not moving memory may (someday, if not now). 
  673. SysBeep is a classic example;  it didn't...it often does now.
  674.  
  675. Any trap may have been patched.  The patch should behave, with respect to
  676. moving memory, no "worse" than the version in ROM (any ROM, by the way). 
  677. But...both shareware and commercial ware messes this up, too.  IMHO:  treat
  678. any trap as moving memory.
  679.  
  680. >       Criteria for judging at the outset of a project whether the hassle
  681. >       of correct HLock/HUnlocking is going to outweigh the benefits of using 
  682. >       NewHandle over NewPtr?
  683.  
  684. Years of experience combined with lucky guesses.
  685.  
  686. >       Methods for debugging CDEVs under System 7? Or is this problem a good 
  687. >       reason to create the interface as a small Application, in this age
  688. >       of MultiFinder and AppleEvents?
  689.  
  690. There's not much reason for writing Control Panels any more, if you only
  691. support System 7 and later.  If you never write one, you never have to
  692. learn how.
  693.  
  694. -- 
  695. John Baxter    Port Ludlow, WA, USA  [West shore, Puget Sound]
  696.    jwbaxter@pt.olympus.net
  697.  
  698. +++++++++++++++++++++++++++
  699.  
  700. >From AIKEN <INRA000@MUSICB.MCGILL.CA>
  701. Date: Sat, 26 Feb 1994 01:13:20 GMT
  702. Organization: McGill University
  703.  
  704. In article <jwbaxter-250294150408@ptpm006.olympus.net> jwbaxter@olympus.net (John W. Baxter) writes:
  705. >In article <francis-250294193316@pinza.demon.co.uk>,
  706. >francis@pinza.demon.co.uk (Francis H. Knight) wrote:
  707. >>    Methods for debugging CDEVs under System 7? Or is this problem a good
  708. >>    reason to create the interface as a small Application, in this age
  709. >>    of MultiFinder and AppleEvents?
  710. >
  711. >There's not much reason for writing Control Panels any more, if you only
  712. >support System 7 and later.  If you never write one, you never have to
  713. >learn how.
  714.  
  715.     A quick note on this: I still feel constrained to write a Control
  716. Panel if I have nothing to put in the Menu Bar of a possible replacement
  717. application. Control Panels still have the advantage of being window-
  718. only and opening in the Finder's layer. If Apple seriously wanted to
  719. junk the whole Control Panel interface, I would love to see a new type
  720. of application: 'mbla' -- menu bar-less app. To open with a face but
  721. without a menu bar. Or will this go away when Apple kills off
  722. application layers alltogether? :-)
  723.  
  724.     Mark Aiken
  725.     inra@musicb.mcgill.ca
  726.  
  727.  
  728. +++++++++++++++++++++++++++
  729.  
  730. >From aep@world.std.com (Andrew E Page)
  731. Date: Sat, 26 Feb 1994 15:08:18 GMT
  732. Organization: The World Public Access UNIX, Brookline, MA
  733.  
  734.  
  735.    Way back when, when I was learing to program a mac(do no ask) I
  736. think the best peice of advice I picked up from a technote or a
  737. BBS(can't remember where), was that when handles are concerned:
  738.  
  739.      IT PAYS TO BE PARANOID.  ALWAYS LOCK THEM BEFORE USING THEM.
  740.  
  741.   When you're using your own data structs in handles sometimes it
  742. becomes a royal pain to be always typing:
  743.  
  744.     HLock((Handle)MyHandle) ;
  745.     HUnlock((Handle)MyHandle) ;
  746.  
  747.   So I created the folowing macros in my personal 'types' file:
  748.  
  749.  
  750. #define HLOCK(h) HLock((Handle)h)
  751. #define HLOCKHI(h) HLockHi((Handle)h)
  752. #define HUNLOCK(h) HUnlock((Handle)h)
  753.  
  754.  
  755.   Save's alot of extra typing, improves the readability of the code.
  756. Always check MemError() afterwards though, Admittedly, it can get
  757. cumbersome, but it's better than spending a couple days of debugging
  758. just to find out you passed a function a bogus handle at some point.
  759.  
  760. foo()
  761. {
  762. MyStruct **MyHnd, *MyPtr ;
  763. OSErr err ;
  764.  
  765.     HLOCK(MyHnd) ;
  766.     if( err = MemError() )
  767.         HandleMemError(err) ;
  768.  
  769.     MyPtr = *MyHnd ;
  770.  
  771.     MyPtr->someData = X ;
  772.     /*
  773.     *   other arcane and silly operations.
  774.     */
  775.     
  776.  
  777.     HUNLOCK(MyHnd) ;
  778.  
  779. }
  780.  
  781.    Lately though I've been using the calls HGetState and HSetState
  782. more frequently, to guarantee that I'm not going to unlock something
  783. that had been locked somewhere else before.  (That's an ouch)
  784.  
  785.  
  786. #define HGETSTATE(h) HGetState(h)
  787. #define HSETSTATE(h, c) HSetState(h, c)
  788.  
  789. foo(MyStruct **MyHnd)
  790. {
  791. MyStruct *MyPtr ;
  792. OSErr err ;
  793. char hndState ;
  794.     
  795.     hndState = HGETSTATE(MyHnd) ;
  796.         HLOCK(MyHnd) ;
  797.         if( err = MemError() )
  798.                 HandleMemError(err) ;
  799.  
  800.         MyPtr = *MyHnd ;
  801.  
  802.         MyPtr->someData = X ;
  803.         /*
  804.         *   other arcane and silly operations.
  805.         */
  806.  
  807.  
  808.         HSETSTATE(MyHnd, hndState) ;
  809.  
  810. }
  811.  
  812.  
  813.    By doing this religiously you can save yourself MUCH trouble
  814. throughout a programming project where you're passing back and forth
  815. alot of data in handles.  
  816.  
  817. -- 
  818. Andrew E. Page   (Warrior Poet) |   Decision and Effort The Archer and Arrow
  819. Mac Consultant                  |     The difference between what we are
  820. Macintosh and DSP Technology    |           and what we want to be.
  821.  
  822. ---------------------------
  823.  
  824. >From gurgle@netcom.com (Pete Gontier)
  825. Subject: When to unlock?
  826. Date: Sat, 26 Feb 1994 22:25:50 GMT
  827. Organization: cellular
  828.  
  829. Submitted-by: gurgle@netcom.com
  830. Archive-name: oHandleLocker.cp
  831.  
  832. francis@pinza.demon.co.uk (Francis H. Knight) writes:
  833.  
  834. >I'm finding it very laborious, and not very creative, to work out where
  835. >to bracket (de-)references to the struct with HLock/HUnlock, given
  836. >that a heap compaction trigger may be hidden within several layers
  837. >of function calls.
  838.  
  839. Essential Secret of Macintosh Programming #412
  840. ----------------------------------------------
  841. Never call HUnlock.
  842.  
  843. Instead, do this:
  844.  
  845.    OSErr WhackHandle (Handle foo)
  846.    {
  847.       OSErr oe = noErr;
  848.  
  849.       char hState = HGetState (foo);
  850.       if (!(oe = MemError ( )))
  851.       {
  852.          HLock (foo);
  853.          if (!(oe = MemError ( )))
  854.          {
  855.             // whack the handle
  856.  
  857.             HSetState (foo,hState);
  858.             if (!oe) oe = MemError ( );
  859.          }
  860.       }
  861.       return oe;
  862.    }
  863.  
  864. The above is laborious, but that's what C++ is for:
  865.  
  866.    class oHandleLocker
  867.    {
  868.          char     fState;
  869.          Handle   fHandle;
  870.  
  871.       public :
  872.  
  873.          oHandleLocker (Handle h)
  874.         { fState = HGetState (h); HLock (h); fHandle = h; }
  875.          ~oHandleLocker (void) // not virtual deliberately
  876.                 { HSetState (fHandle, fState); }
  877.    }
  878.  
  879.    void WhackHandle (Handle h)
  880.    {
  881.       oHandleLocker locked (h);
  882.  
  883.       // whack the handle;
  884.       // it will automagically be unlocked at function exit
  885.    }
  886.  
  887. Note that the C++ version omits calls to MemError; that's the price you
  888. pay for a C++ compiler without exceptions. Most people don't bother with
  889. MemError when calling HLock/HGetState/HSetState anyway. I do, but that's
  890. neither here nor there. Just be aware of it.
  891.  
  892. Also, oHandleLocker might benefit (depending on your world-view) from
  893. dealing with 'void *' instead of 'Handle'. I've used Handle here in
  894. order to avoid explaining why 'void *' might be useful.
  895.  
  896. (By the way, none of the enclosed code has been compiled, but it should
  897. only require minimal changes, and the principles are sound; I have used
  898. them before.)
  899. -- 
  900.  Pete Gontier, CTO, Integer Poet Software; gurgle@netcom.com
  901.  
  902. ---------------------------
  903.  
  904. End of C.S.M.P. Digest
  905. **********************
  906.  
  907.  
  908.  
  909.